﻿using System;
using System.Collections.Generic;

using Microsoft.Xna.Framework;

namespace Nine
{
	public abstract class Module : IModule, IUpdateable
	{
		#region IUpdateable Members

		#region Enabled
		private bool enabled = true;

		public bool Enabled
		{
			get { return this.enabled; }
			set
			{
				if (this.enabled != value)
				{
					this.enabled = value;
					if (this.EnabledChanged != null)
						this.EnabledChanged(this, EventArgs.Empty);
				}
			}
		}

		public event EventHandler<EventArgs> EnabledChanged;
		#endregion

		#region UpdateOrder
		private int updateOrder = 0;

		public int UpdateOrder
		{
			get { return this.updateOrder; }
			set
			{
				if (this.updateOrder != value)
				{
					this.updateOrder = value;
					if (this.UpdateOrderChanged != null)
						this.UpdateOrderChanged(this, EventArgs.Empty);
					if (this.Entity is Entity)
						(this.Entity as Entity).sort = true;
				}
			}
		}

		public event EventHandler<EventArgs> UpdateOrderChanged;
		#endregion

		#endregion

		#region IDrawable Members

		#region Visible
		private bool visible = true;

		public bool Visible
		{
			get { return this.visible; }
			set
			{
				if (this.visible != value)
				{
					this.visible = value;
					if (this.VisibleChanged != null)
						this.VisibleChanged(this, EventArgs.Empty);
				}
			}
		}
		public event EventHandler<EventArgs> VisibleChanged;
		#endregion

		#region DrawOrder
		private int drawOrder = 0;

		public int DrawOrder
		{
			get { return this.drawOrder; }
			set
			{
				if (this.drawOrder != value)
				{
					this.drawOrder = value;
					if (this.DrawOrderChanged != null)
						this.DrawOrderChanged(this, EventArgs.Empty);
					if (this.Entity is Entity)
						(this.Entity as Entity).sort = true;
				}
			}
		}

		public event EventHandler<EventArgs> DrawOrderChanged;
		#endregion

		#endregion

		public IEntity Entity { get; internal set; }

		public virtual void Update(GameTime Gt) { }

		public virtual void Draw(GameTime Gt) { }
	}
}
